﻿<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="MyProfile.aspx.vb" Inherits="MyProfile" %>
<%@ Register src="CustomerInfo.ascx" tagname="CustomerInfo" tagprefix="uc1" %>
<%@ Register src="CreditCard.ascx" tagname="CreditCard" tagprefix="uc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="myprofile">
    <asp:Label ID="lblMyUserID" runat="server" Visible="false" />
    <asp:Label ID="lblMyCustomerID" runat="server" Visible="false" />
    <center>
    <h1>My Account</h1>  
        <ajaxToolkit:Accordion ID="Accordion1" runat="server" 
         SuppressHeaderPostbacks="true" RequireOpenedPane="false" ContentCssClass="accordbody" 
            FramesPerSecond="30" HeaderCssClass="accordhead" HeaderSelectedCssClass="" 
            TransitionDuration="250">
            <Panes>
                <ajaxToolkit:AccordionPane ID="pane1" runat="server">
                    <Header>Profile Information</Header>
                    <Content>
                        <uc1:CustomerInfo Mode="Edit" ID="CustomerInfo1" runat="server" />
                    </Content>
                </ajaxToolkit:AccordionPane>
                <ajaxToolkit:AccordionPane ID="pane2" runat="server">
                    <Header>Order History</Header>
                    <Content>
                        <asp:UpdatePanel ID="upnlCustomerOrders" runat="server">
                            <ContentTemplate>
                            <br />
                                <asp:GridView ID="gvwOrders" runat="server" CssClass="Gridview" 
                                AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" 
                                DataKeyNames="OrderID" DataSourceID="adsOrders">
                                    <Columns>
                                        <asp:BoundField DataField="OrderID" HeaderText="Order#" 
                                            ReadOnly="True" SortExpression="OrderID" />
                                        <asp:BoundField DataField="OrderDate" HeaderText="Order Date" 
                                            SortExpression="OrderDate" />
                                        <asp:BoundField DataField="NumProducts" HeaderText="Products" 
                                            SortExpression="NumProducts" />
                                        <asp:BoundField DataField="SumOfAmount" HeaderText="Total" 
                                            SortExpression="SumOfAmount" />
                                        <asp:TemplateField>
                                            <ItemTemplate>
                                                <center>
                                                <asp:Label ID="lblOrderID" runat="server" Text='<%# Eval("OrderID") %>' Visible="false" />
                                                <asp:LinkButton CommandName="Select" Text="Cancel" CausesValidation="false"
                                                        ID="btnCancel" runat="server" onclick="btnCancel_Click"/>
                                                <ajaxToolkit:ModalPopupExtender BackgroundCssClass="modalback" OkControlID="btnModOk" ID="modCancel" TargetControlID="btnCancel" 
                                                PopupControlID="pnlOrderDetails" runat="server" />
                                                <asp:Panel CssClass="modal" BorderStyle="Double" ScrollBars="Auto" BorderColor="#970C49" BackColor="#ffeff6" Width="500px" runat="server" ID="pnlOrderDetails">
                                                    <div style="margin:10px;">
                                                    <asp:Label runat="server" ID="lblLineErrors" />
                                                    <asp:GridView CssClass="Gridview" ID="gvwOrderDetail" DataSourceID="adsOrderLines"  
                                                        AllowSorting="false" DataKeyNames="OrderLineID" 
                                                        AllowPaging="false" AutoGenerateColumns="false" runat="server" >
                                                        <Columns>
                                                            <asp:BoundField DataField="OrderLineID" HeaderText="Rec#" 
                                                                ReadOnly="True" SortExpression="OrderLineID" />
                                                            <asp:BoundField DataField="ProductName" HeaderText="Product" 
                                                                SortExpression="ProductName" />
                                                            <asp:BoundField DataField="Qty" HeaderText="Qty" 
                                                                SortExpression="Qty" />
                                                            <asp:BoundField DataField="Amount" HeaderText="Amount" 
                                                                SortExpression="Amount" />
                                                            <asp:TemplateField>
                                                                <ItemTemplate>
                                                                    <asp:Label ID="lblCanceled" runat="server" ToolTip='<%#Eval("CancelDate") %>' Text="Cancelled" Visible='<%#IIF(Eval("isCanceled"),True, False) %>' />
                                                                    <asp:Label ID="lblShipped" runat="server" ToolTip='<%#Eval("ShipDate") %>' Text="Shipped" Visible='<%#IIF(Eval("isShipped"),True, False) %>' />
                                                                    <asp:Button CommandName="CancelLine" Visible='<%#IIF(Eval("isShipped") or Eval("isCanceled"),False, True) %>' 
                                                                        CommandArgument='<%# Eval("OrderLineID") %>' ID="btnCancelLine" runat="server" 
                                                                        Text="Cancel" CausesValidation="false" OnClick="btnCancelLine_Click" />
                                                                </ItemTemplate>
                                                            </asp:TemplateField>
                                                        </Columns>
                                                    </asp:GridView>
                                                    <asp:AccessDataSource ID="adsOrderLines" runat="server" 
                                                    DataFile="~/App_Data/GotPink.accdb"   
                                                    SelectCommand="SELECT OrderLine.OrderLineID, Products.ProductName, OrderLine.Qty, OrderLine.Amount, OrderLine.isCanceled, OrderLine.isShipped, OrderLine.ShipDate, OrderLine.CancelDate
                                                        FROM Products INNER JOIN OrderLine ON Products.ProductID = OrderLine.ProductID
                                                        WHERE OrderID = ?" >
                                                        <SelectParameters>
                                                            <asp:ControlParameter ControlID="lblOrderID" Name="OrderID" PropertyName="Text" DbType="Int32" />
                                                        </SelectParameters>
                                                    </asp:AccessDataSource>
                                                    <br />
                                                    <asp:Button ID="btnModOk" runat="server" Text="Close" />
                                                    <br />
                                                    </div>
                                                </asp:Panel>
                                                </center>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                    <EmptyDataTemplate>
                                        There are no orders.  Please place an order.
                                    </EmptyDataTemplate>
                                </asp:GridView>
                            <asp:AccessDataSource ID="adsOrders" runat="server" 
                            DataFile="~/App_Data/GotPink.accdb"   
                            SelectCommand="SELECT Orders.OrderID, Orders.OrderDate, Count(OrderLine.ProductID) AS NumProducts, Sum(OrderLine.Amount) AS SumOfAmount
                            FROM Orders INNER JOIN OrderLine ON Orders.OrderID = OrderLine.OrderID
                            WHERE ([CustomerID] = ?)
                            GROUP BY Orders.OrderID, Orders.OrderDate" >
                                <SelectParameters>
                                    <asp:ControlParameter ControlID="lblMyCustomerID" Name="CustomerID" PropertyName="Text" DbType="Int32" />
                                </SelectParameters>
                            </asp:AccessDataSource>
                            <br />
                            </ContentTemplate>
                            <Triggers>
                                <asp:AsyncPostBackTrigger ControlID="gvwOrders" EventName="RowCommand" />
                            </Triggers>
                        </asp:UpdatePanel>
                    </Content>
                </ajaxToolkit:AccordionPane>
                <ajaxToolkit:AccordionPane ID="pane3" runat="server">
                    <Header>Payment Information</Header>
                    <Content>
                        <asp:UpdatePanel ID="upnlCards" UpdateMode="Conditional" runat="server">
                            <ContentTemplate>
                            <asp:GridView ID="gvwCards" runat="server" AllowPaging="True" CssClass="Gridview" DataKeyNames="CardID"
                                    AutoGenerateColumns="False" DataSourceID="adsCards">
                                <Columns>
                                    <asp:BoundField DataField="CardID" HeaderText="CardID" 
                                        SortExpression="CardID" Visible="false" />
                                    <asp:BoundField DataField="CardType" HeaderText="CardType" 
                                        SortExpression="CardType" />
                                    <asp:TemplateField HeaderText="Card">
                                        <ItemTemplate>
                                            <asp:Label ID="lblCardNum" runat="server" Text='<%#GetMaskedString(Eval("CardNumber")) %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Expiration">
                                        <ItemTemplate>
                                            <asp:Label ID="lblExpire" runat="server" Text='<%#Eval("ExpirationMonth") & "-" & Eval("ExpirationYear") %>'></asp:Label>
                                        </ItemTemplate> 
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="NameOnCard" HeaderText="Name" 
                                        SortExpression="NameOnCard" />
                                    <asp:CommandField CausesValidation="false" ButtonType="Link" DeleteText="Remove" ShowDeleteButton="true" />
                                </Columns>
                                <EmptyDataTemplate>
                                    There are no cards on file.  Please place an order.
                                </EmptyDataTemplate>
                            </asp:GridView>
                            <asp:AccessDataSource ID="adsCards" runat="server" 
                                    DataFile="~/App_Data/GotPink.accdb"  
                                    DeleteCommand="UPDATE CustomerCards SET isDeleted=1 WHERE CardID = ?"
                                    SelectCommand="SELECT [CardID], [CardType], [CardNumber], [ExpirationMonth], [NameOnCard], [ExpirationYear] FROM [CustomerCards] WHERE isDeleted=0 and ([CustomerID] = ?)">
                                <SelectParameters>
                                    <asp:ControlParameter ControlID="lblMyCustomerID" Name="CustomerID" 
                                        PropertyName="Text" Type="Int32" />
                                </SelectParameters>
                                <DeleteParameters>
                                    <asp:Parameter Name="CardID" Type="Int32" />
                                </DeleteParameters>
                                </asp:AccessDataSource>
                                <asp:LinkButton Text="Add Card" CausesValidation="false" ID="btnAddCard" runat="server"/>
                                <ajaxToolkit:ModalPopupExtender BackgroundCssClass="modalback" ID="modCardAdd" TargetControlID="btnAddCard" 
                                PopupControlID="pnlAddCard" runat="server" />
                                <asp:Panel CssClass="modal" BorderStyle="Double" ScrollBars="Auto" BorderColor="#970C49" BackColor="#ffeff6" Width="500px" runat="server" ID="pnlAddCard">
                                    <uc2:CreditCard ID="CreditCard1" Mode="Insert" ShowButton="true" runat="server" />
                                    <br />
                                    <asp:Button ID="btnModAddOk" runat="server" Text="Close" />
                                </asp:Panel>        
                            </ContentTemplate>
                            <Triggers>
                                <asp:AsyncPostBackTrigger ControlID="gvwCards" EventName="RowCommand" />
                                <asp:AsyncPostBackTrigger ControlID="btnModAddOk" EventName="Click" />
                            </Triggers>
                        </asp:UpdatePanel>
                        <br />
                    </Content>
                </ajaxToolkit:AccordionPane>
            </Panes>
        </ajaxToolkit:Accordion>
    </center>
</div>
<br />
</asp:Content>


